<template>
	<view class="box">
		<th-autograph :is-download="false" @submit="getFile" canvas-id="autograph">
		</th-autograph>
	</view>
</template>

<script>
	import thAutograph from "@/pagesLive/components/th-autograph/components/th-autograph/th-autograph.vue"
	export default {
		components: {
			thAutograph
		},
		methods: {
			getFile(path) {
				this.uploadFile(path)
			},
			uploadFile: function(tempList) {
				let self = this;
				let params = {
					token: uni.getStorageSync('token'),
					appId: self.getAppId()
				};
				uni.showLoading({
					title: '签名生成中'
				});
				uni.uploadFile({
					url: self.websiteUrl + '/api/front/file/upload/image',
					filePath: tempList,
					name: 'iFile',
					formData: params,
					header: {
						'appId': self.getAppId()
					},
					success: function(res) {
						uni.hideLoading();
						let data = JSON.parse(res.data)
						console.log(data.data.filePath);
						self.goBack(data.data.filePath)
					},
					complete: function() {
						uni.hideLoading();
					}
				});
			},
			goBack(url) {
				let pages = getCurrentPages() //获取所有页面栈的实例列表
				let nowPage = pages[pages.length - 1] //当前页面的实例
				let prevPage = pages[pages.length - 2] //上一个页面的实例
				prevPage.$vm.signatureimg = url //更改上一个页面的数据
				uni.navigateBack({
					delta: 1 //返回上一页
				})
			}
		}
	}
</script>

<style>
	page {
		width: 100%;
		height: 100%;
	}

	.box {
		width: 100%;
		height: 100%;
	}
</style>